#ifndef SELECTSCENE_H
#define SELECTSCENE_H
enum SelBtn
{
    FIRST_SB,
    SECOND_SB,
    THIRD_SB,
    BACK_SB,
    NULL_SB,
}selBtn(NULL_SB);

class SelectScene : public QGraphicsScene
{
public:
    explicit SelectScene(QObject *parent = 0):
           QGraphicsScene(parent)
       {
           setSceneRect(0.0, 0.0, 640.0, 360.0);

           m_bgItem = new ImageItem(QImage(":/image/sel/start_bg.jpg"),
                                    QRect(QPoint(0,0),QImage(":/image/sel/start_bg.jpg").size()));
           m_bgItem->setZValue(0.0);
           m_bgItem->setPos(0.0,0.0);
           addItem(m_bgItem);

           m_backItem = new ImageItem(*resources::m_selBackImage,
                                      QRect(QPoint(0,0),resources::m_selBackImage->size()));
           m_backItem->setZValue(1.0);
           m_backItem->setPos(482.0,283.0);
           addItem(m_backItem);

           m_firstItem = new ImageItem(*resources::m_selFirstImage,
                                       QRect(QPoint(0,0),resources::m_selFirstImage->size()));
           m_firstItem->setZValue(1.0);
           m_firstItem->setPos(51.0,57.0);
           addItem(m_firstItem);

           m_secondItem = new ImageItem(*resources::m_selSecondImage,
                                        QRect(QPoint(0,0),resources::m_selSecondImage->size()));
           m_secondItem->setZValue(1.0);
           m_secondItem->setPos(234.0,57.0);
           addItem(m_secondItem);

           m_thirdItem = new ImageItem(*resources::m_selThirdImage,
                                       QRect(QPoint(0,0),resources::m_selThirdImage->size()));
           m_thirdItem->setZValue(1.0);
           m_thirdItem->setPos(417.0,57.0);
           addItem(m_thirdItem);
       }

    ~SelectScene()
    {}

    void mousePressEvent(QGraphicsSceneMouseEvent *event)
    {
        if(m_firstItem->isUnderMouse())
        {
            if(resources::m_bplaysound)
            {
                resources::m_sound->play(5);
            }
            m_firstItem->setImage(*resources::m_selFirstpImage);
            selBtn = FIRST_SB;
        }
        else if(m_secondItem->isUnderMouse())
        {
            if(resources::m_bplaysound)
            {
                resources::m_sound->play(5);
            }
            m_secondItem->setImage(*resources::m_selSecondpImage);
            selBtn = SECOND_SB;
        }
        else if(m_thirdItem->isUnderMouse())
        {
            if(resources::m_bplaysound)
            {
                resources::m_sound->play(5);
            }
            m_thirdItem->setImage(*resources::m_selThirdpImage);
            selBtn = THIRD_SB;
        }
        else if(m_backItem->isUnderMouse())
        {
            if(resources::m_bplaysound)
            {
                resources::m_sound->play(5);
            }
            m_backItem->setImage(*resources::m_selBackpImage);
            selBtn = BACK_SB;
        }
    }

    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
    {
        switch(selBtn)
        {
        case FIRST_SB:
        {
            m_firstItem->setImage(*resources::m_selFirstImage);
            if(m_firstItem->isUnderMouse())
            {
                resources::m_icurlevel = 0;
                resources::SetGame();
            }
        }
        break;
        case SECOND_SB:
        {
            m_secondItem->setImage(*resources::m_selSecondImage);
            if(m_secondItem->isUnderMouse())
            {
                resources::m_icurlevel = 1;
                resources::SetGame();
            }
        }
        break;
        case THIRD_SB:
        {
            m_thirdItem->setImage(*resources::m_selThirdImage);
            if(m_thirdItem->isUnderMouse())
            {
                resources::m_icurlevel = 2;
                resources::SetGame();
            }
        }
        break;
        case BACK_SB:
        {
            m_backItem->setImage(*resources::m_selBackImage);
            if(m_backItem->isUnderMouse())
            {
                resources::SetMain();
            }
        }
        break;
        default:
            break;
        }
    }

public:
    ImageItem*  m_bgItem;
    ImageItem*  m_backItem;
    ImageItem*  m_firstItem;
    ImageItem*  m_secondItem;
    ImageItem*  m_thirdItem;
};

#endif // SELECTSCENE_H
